%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% This file is part of the book
%%
%% Algorithmic Graph Theory
%% http://code.google.com/p/graph-theory-algorithms-book/
%%
%% Copyright (C) 2009--2011 Minh Van Nguyen <nguyenminh2@gmail.com>
%%
%% See the file COPYING for copying conditions.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\DontPrintSemicolon
\SetAlgoNoLine
%%
%% input
\KwIn{An ordered tree $T$ on $n > 0$ vertices.}
%%
%% output
\KwOut{A list of the vertices of $T$ in level-order.}
\BlankLine
%%
%% algorithm body
$L \assign [\,]$\;
$Q \assign$ empty queue\;
$r \assign$ root of $T$\;
$\enqueue(Q, r)$\;
\While{$\length(Q) > 0$}{
  $v \assign \dequeue(Q)$\;
  $\append(L, v)$\;
  $[u_1, u_2, \dots, u_k] \assign$ ordering of children of $v$\;
  \For{$i \assign 1, 2, \dots, k$}{
    $\enqueue(Q, u_i)$\;
  }
}
\Return $L$\;
